package movie.test.order;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import movie.test.as.order.service.OrderService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;


/**
 * 定位是一家电影院
 * 添加购物车
 * @author guolingling
 *
 */
@RestController
@RequestMapping("/orderController")
public class OrderController {

	private static Logger logger = LoggerFactory.getLogger(OrderController.class);
	
	@Autowired
	private OrderService orderServiceImpl;
	
	/**
	 * 添加订单
	 * @param objs
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/addOrderInfo")
	public Object addOrderInfo(@RequestBody JSONObject objs,HttpServletRequest request){
		
		try{
			logger.debug("添加购物车开始");
			Map<String, Object> addOrderInfo = orderServiceImpl.addOrderInfo(objs);
			logger.info("添加购物车结束");
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put("result",addOrderInfo);
			return resultMap;
		}catch(Exception e){
			e.printStackTrace();
		}
		
	  return "";
	}
	
	/**
	 * 订单提交
	 * @param objs
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getOrderByUserId")
	public Object getOrderByUserId(HttpServletRequest request){
		
		try{
			logger.debug("查询订单开始");
			List<Map<String, Object>> orderList = orderServiceImpl.getOrderByUserId();
			logger.info("查询订单结束");
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put("result",orderList);
			return resultMap;
		}catch(Exception e){
			e.printStackTrace();
		}
		
	  return "";
	}
	
	/**
	 * 订单提交
	 * @param objs
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/updateOrderById")
	public Object updateOrderById(@RequestBody JSONObject objs,HttpServletRequest request){
		
		try{
			logger.debug("更新订单开始");
			int count = orderServiceImpl.updateOrderById(objs);
			logger.info("更新订单结束");
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put("result",count);
			return resultMap;
		}catch(Exception e){
			e.printStackTrace();
		}
		
	  return "";
	}
	
	/**
	 * 订单提交
	 * @param objs
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/updateSubmitOrderById")
	public Object updateSubmitOrderById(@RequestBody JSONObject objs,HttpServletRequest request){
		
		try{
			logger.debug("支付订单");
			int count = orderServiceImpl.updateSubmitOrderById(objs);
			logger.info("支付订单成功");
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put("result",count);
			return resultMap;
		}catch(Exception e){
			e.printStackTrace();
		}
		
	  return "";
	}
	
/*	*//**
	 * 更新座位信息
	 */
	@ResponseBody
	@RequestMapping("/updateSeatsById")
	public Object updateSeatsById(@RequestBody JSONObject objs,HttpServletRequest request){
		
		try{
			logger.debug("更新座椅信息");
			int count = orderServiceImpl.updateSeatsById(objs);
			logger.info("更新座椅成功");
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put("result",count);
			return resultMap;
		}catch(Exception e){
			e.printStackTrace();
		}
		
	  return "";
	}
	/**
	 * 查询所有的订单
	 * @param objs
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getOrderListsByUserId")
	public Object getOrderListsByUserId(HttpServletRequest request){
		
		try{
			logger.debug("查询我的订单开始");
			List<Map<String, Object>> orderList = orderServiceImpl.getOrderListsByUserId();
			logger.info("查询我的订单结束");
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put("result",orderList);
			return resultMap;
		}catch(Exception e){
			e.printStackTrace();
		}
		
	  return "";
	}
}
